<?php define('SIDEBAR', FALSE);?>
<?php /* 
Template Name: (03) Page with athletes
*/ ?>
<?php get_header(); ?>	

	
	<?php // Start spesial pagecontent
	$char_array = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','æ','ø','å');
	$char = $char_array[0];
	// Check for $_GET variables
	if (isset($_GET['char']) and in_array($_GET['char'], $char_array)) {
    	$char = $_GET['char'];
	} 
	function char_menu($return = false) {
		global $char, $char_array;
		$output = "<p class=\"charmenu\">";
		$script_location = htmlspecialchars($_SERVER['SCRIPT_URI']);
		foreach($char_array as $achar) {
			if($achar != $char) $output .= "<a href=\"$script_location?char=$achar\">$achar</a> ";
			else $output .= "$achar ";
		}
		$output .= "</p>";
		if($return) return $output;
		echo $output;
	}
	?>
	
	<?php
	global $wpdb;   // Give wpdb with global scope
	$sql = "SELECT * FROM athlete 
		WHERE athlete.name LIKE'$char%' order by athlete.name desc"; 
	
	$results = $wpdb->get_results($sql);  // Run our query, getting results as an object
 	//$sql_year = 'SELECT distinct year from record order by year desc';
	//$all_years = $wpdb->get_results($sql_year);	
?>

<h2>Utøvere på <?php echo $char; ?></h2>
<?php char_menu(); ?>
<div class="athlete-wrapper">
<?php foreach($results as $result): ?>
<div class="athlete">
<a rel="lightbox" href="<?php echo PROFIL_DIR . $result->picfile; ?>">
	<img src="<?php echo PROFIL_DIR . $result->picfile; ?>" title="<?php echo $result->name; ?>"/>
</a>
<h3><?php echo $result->name; ?></h3>
<p><span class="label">Klubb:</span> <?php echo $result->team; ?></p>
<p><a href="<?php bloginfo('url') ?>/resultater/?query=<?php echo $result->name; ?>" alt="Trykk her for å se alle Ironman denne utøveren har fullført">Se ironman resultater</a></p>
</div>
<?php endforeach; ?>
</div>

<?php get_footer(); ?>